hysop.core.graph.computational_node module

@file graph_operator.py Base for directionally splitted advection solvers (pure-python and GPU version).

class hysop.core.graph.computational_node.ComputationalGraphNode(input_fields=None, output_fields=None, input_params=None, output_params=None, input_tensor_fields=None, output_tensor_fields=None, name=None, pretty_name=None, method=None, to_be_skipped_func=None, **kwds)[source]

Bases: OperatorBase

Interface of an abstract computational graph node.

Initialize a ComputationalGraphNode.

Parameters:
  • input_fields (dict, optional) – input fields as a dictionnary (see Notes).

  • output_fields (dict, optional) – output fields as a dictionnary (see Notes).

  • input_params (array like of hysop.parameters.Parameter or dict, optional (see Notes)) – input parameters as a set or a dictionnary.

  • output_params (array like of hysop.parameters.Parameter or dict, optional (see Notes)) – output parameters as a set or a dictionnary.

  • input_tensor_fields (tuple, optional) – input tensor fields as a tuple. If given, input_fields is assumed to contain only ScalarFields. Else they are deduced from input_fields.

  • output_tensor_fields (tuple, optional) – output tensor fields as a tuple. If given, output_fields is assumed to contain only ScalarFields. Else they are deduced from output_fields.

  • name (str, optional) – name of this node (string), optional, defaults to top class name. Default name will be the top class name (ie. self.__class__.__name__).

  • pretty_name (str, optional) – Pretty name of this node (string), optional, defaults to name.

  • method (dict, optional) – user method specification for this graph node, optional, defaults to None.

  • kwds – arguments for base classes (mpi_params and io_params).

name

name of this node (used for printing and display purpose).

Type:

str

pretty_name

Pretty name of this node (used for printing and display purpose).

Type:

str

input_fields

input fields as a dictionnary (see Notes).

Type:

dict

output_fields

output fields as a dictionnary (see Notes).

Type:

dict

base_method

base method specification for this graph node.

Type:

dict

initialized

flag set after initialize() has been called.

Type:

bool

discretized

flag set after discretize() has been called.

Type:

bool

ready

flag set after setup() has been called.

Type:

bool

method

method, set after initialize() has been called.

Type:

dict(MethodKey, MethodValue)

input_field_requirements

input constraints, set after initialize() has been called.

Type:

dict(Field, DiscreteFieldRequirements)

output_field_requirements = {}

output constraints, set after initialize() has been called.

Notes

For the input and output fields, the keys of the dicts have to be of type hysop.fields.continuous_field.Field. and the values should consist of hysop.topology.topology_descriptor.TopologyDescriptors instances ie. an already defined topology or a topology descriptor.

VectorFields and TensorFields are expanded to ScalarFields.

For input and output parameters, in case of dict, the key is the actual Parameter and the value must be an MPIParams, or None

Giving the following keywords as inputs (in **kwds) will throw a ValueError:

input_vars, output_vars, variables, iwork, rwork, work, backend

About the method parameter:

One can not directly use the method parameter after this call. User method is put into attribute base_method awaiting the initialization step. See ComputationalGraphNode.handle_method() to see how method is handled.

abstract apply(simulation=None, **kwds)[source]

Abstract method that should be implemented. Applies this node (operator, computational graph operator…).

abstract available_methods()[source]

Returns the available methods of this node. This should return a dictionary of method as keys and possible values as a scalar or an iterable. See hysop.types.InstanceOf to support specific class types. This is used to check user method input.

check()[source]

Check if node was correctly initialized. By default this checks variables, topologies and support.

abstract default_method()[source]

Returns the default method of this node. Default methods should be compatible with available_methods. If the user provided method dictionnaty misses some method keys, a default value for this key will be extracted from the default one.

discretize()[source]

Discretize this operator. By default this just sets the self.discretized flag to True. Once this flag is set one may call ComputationalGraphNode.get_work_properties() and ComputationalGraphNode.setup().

dump_inputs(fields=None, io_params=None, filename=None, frequency=None, fileformat=None, io_leader=None, **op_kwds)[source]

Tell this operator to dump some of its inputs before apply is called.

Target folder, file, dump frequency and other io pameters are passed trough io_params or as keywords.

dump_outputs(fields=None, io_params=None, filename=None, frequency=None, fileformat=None, io_leader=None, **op_kwds)[source]

Tell this operator to dump some of its outputs after apply is called.

Target folder, file, dump frequency and other io pameters are passed trough instance io_params of this parameter or as keywords.

classmethod expand_tensor_fields(fields)[source]
finalize(**kwds)[source]

Cleanup this node (free memory from external solvers, …) By default, this does nothing

get_and_set_field_requirements()[source]

Calls get_field_requirements() on current node and set self.field_requirements.

get_backends()[source]

Returns all the backends used in this operator as a set.

get_domains()[source]

Returns all the domains used in this operator. Domains are keys and values are operators that have variables defined on this domain. If this node has no domain (ie. no input or output variables), if fills the ‘None’ domain.

abstract get_field_requirements()[source]

Called just after handle_method(), ie self.method has been set. Topology requirements are:

  1. min and max ghosts for each input and output variables

  2. allowed splitting directions for cartesian topologies

3) required local and global transposition state, if any. and more

They are stored in self.input_field_requirements and self.output_field_requirements.

Keys are continuous fields and values are of type hysop.fields.field_requirement.DiscreteFieldRequirements

get_input_discrete_field(field)[source]
Helper function to get a discretized input field:

*Get a DiscreteScalarField from an input ScalarField. *Get a DiscreteTensorField from an input TensorField.

get_input_field_requirements()[source]

Returns input field requirements for this node.

get_node_requirements()[source]

Called after get_field_requirements to get global node requirements.

get_output_discrete_field(field)[source]
Helper function to get a discretized output field:

*Get a DiscreteScalarField from an output ScalarField. *Get a DiscreteTensorField from an output TensorField.

get_output_field_requirements()[source]

Returns output field requirements for this node.

classmethod get_topo_descriptor(variables, field)[source]
classmethod get_topo_discretization(variables, field)[source]
get_topologies()[source]

Returns all the topologies used in this operator. Topologies are organized by backend in a dictionnary.

get_work_properties()[source]

Returns extra memory requirements of this node. This allows operators to request for temporary buffers that will be shared between operators in a graph to reduce the memory footprint and the number of allocations. By default this returns None, meanning that this node requires no extra buffers.

handle_method(method)[source]

Method automatically called during initialization. This allow to extract method values after method preprocessing. Method preprocessing means:

  1. complete user input with compatible top graph user inputs

  2. complete the resulting dictionnary with the node default_method

  3. check method against available_methods.

The result of this process is fed as argument of this function.

handle_topologies(input_topology_states, output_topology_states)[source]

Called after all topologies have been set up.

Topologies are available as values of self.input_fields and self.output_fields and are mapped by continuous Field.

In addition input_topology_states are passed as argument contains input discrete topology states and output topology states that the graph builder determined. All input states and output topology states have to comply with the operator field requirements obtained with self.get_field_requirements().

initialize(topgraph_method=None, **kwds)[source]

Initialize this node.

Initialization step sets the following variables:

*self.method, *self.input_field_requirements *self.output_field_requirements *self.initialized

It returns self.method.

Order of execution is:

self.pre_initialize() self._setup_method() self.handle_method() self.get_field_requirements() self._initialized = True self.post_initialize()

See ComputationalGraphNode.handle_method() to see how user method is handled. See ComputationalGraphNode.get_field_requirements() to see how topology requirements are handled.

After this method has been handled by all operators, initialization collects min and max ghosts required by each operators which will be usefull in the discretiezation step to automatically build topologies or check against user supplied topologies.

This function also sets the self.initialized flag to True (just before post initialization). Once this flag is set one may call ComputationalGraphNode.discretize().

property input_field_requirements

Returns input field requirements for this node.

property is_domainless

Return True if this node has no input nor output fields.

iter_input_discrete_fields(with_scalars=True, with_tensors=True, as_scalars=False)[source]

Iterate over all input (field, discrete_field) pairs. By default iterate over all tensors and scalars unless only_scalars or only_tensors is specified.

as_scalars will ravel all tensors to scalars.

iter_input_fields(with_scalars=True, with_tensors=True, as_scalars=False)[source]

Iterate over all input fields. By default iterate over all tensors and scalars unless only_scalars or only_tensors is specified.

as_scalars will ravel all tensors to scalars.

iter_output_discrete_fields(with_scalars=True, with_tensors=True, as_scalars=False)[source]

Iterate over all output (field, discrete_field) pairs. By default iterate over all tensors and scalars unless only_scalars or only_tensors is specified.

as_scalars will ravel all tensors to scalars.

iter_output_fields(with_scalars=True, with_tensors=True, as_scalars=False)[source]

Iterate over all output fields. By default iterate over all tensors and scalars unless only_scalars or only_tensors is specified.

as_scalars will ravel all tensors to scalars.

long_description()[source]
property node_tag

Return a tag of this node as a string. Cannot be used to differenciate nodes as some operators may have the same name.

property output_field_requirements

Returns output field requirements for this node.

post_initialize(**kwds)[source]

Function called after initialization, can be used to execute routines after handle_method has been called. By default this does nothing.

pre_initialize(**kwds)[source]

Function called before initialization, can be used to alter variables set in __init__ like input_fields or output_fields. By default this does nothing.

setup(work)[source]

Setup temporary buffer that have been requested in get_work_properties(). This function may be used to execute post allocation routines. This sets self.ready flag to True. Once this flag is set one may call ComputationalGraphNode.apply() and ComputationalGraphNode.finalize().

classmethod supports_mpi()[source]

Return True if this operator was implemented to support multiple mpi processes.

classmethod supports_multiple_field_topologies()[source]

Should return True if an input field that is also an output field can have an input topology different from its output topology. This is usefull in Redistribute like operators. If this returns True this implies supports_multiple_topologies(). It also implies that self.variables[field] may return a set of topologies. In this case one can recover input and output topologies by using self.input_fields[field] and self.output_fields[field]. In addition one can find such fields by using the list self.multi_topo_fields which is set after ComputationalGraphNode.initialize() has been called.

classmethod supports_multiple_topologies()[source]

Should return True if this node supports multiple topologies.

hysop.core.graph.computational_node.base_initialized(f)[source]
hysop.core.graph.computational_node.to_be_skipped_default(*args, **kwargs)[source]

Default function for skipping operator’s apply

hysop.core.graph.computational_node.topology_handled(f)[source]